# 封装注册登录接口

from config import HOST

class ApiRegisterLogin:
    #初始化
    def __init__(self,session):
        #获取session对象
        self.session = session
        # 图片验证码URL
        self.__url_img_code = HOST + "/common/public/verifycode1/{}"
        # 短信验证码URL
        self.__url_phone_code = HOST + "/member/public/sendSms"
        # 注册接口URL
        self.__url_register = HOST + "/member/public/reg"
        # 登录接口URL
        self.__url_login = HOST + "/member/public/login"
        # 查询登录状态URL
        self.__url_login_status = HOST + "/member/public/islogin"


    #获取图片验证码接口
    def api_img_code(self,random):
        return self.session.get(url=self.__url_img_code.format(random))

    # 获取短信验证码接口
    def api_phone_code(self, phone, imgVerifyCode):
        data={
            "phone": phone,
            "imgVerifyCode": imgVerifyCode,
            "type": "reg"
        }
        return self.session.post(url=self.__url_phone_code,data=data)

    #注册接口
    def api_register(self,phone,password,verifycode,phone_code):
        data={
            "phone": phone,
            "password": password,
            "verifycode": verifycode,
            "phone_code": phone_code,
            "dy_server": "on",
            "invite_phone": ""
        }
        return self.session.post(url=self.__url_register,data=data)

    #登录接口
    def api_login(self, keywords="13600001111", password="test123"):
        data={
            "keywords": keywords,
            "password": password,
        }
        return self.session.post(url=self.__url_login,data=data)

    #查询登录状态接口
    def api_login_status(self):
        return self.session.post(url=self.__url_login_status)




